package zzz.jsondemo;





import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.io.FileUtils;
import org.omg.CORBA.Object;


import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
 * Created by 隼 on 2017/5/17.
 */
public class readJson {
    public static void main(String[] args) throws IOException {
        File file=new File("I:\\MyIDEACeit\\SpringmvcDemo\\src\\main\\java\\zzz\\jsondemo\\test.json");
        String content= FileUtils.readFileToString(file);

        JSONObject jsonObject=new JSONObject().fromObject(content);
        System.out.println(jsonObject.getString("name")+"\n"+jsonObject.getBoolean("has_girlfriend"));
        JSONArray majorArray=jsonObject.getJSONArray("major");
        Iterator iterator=majorArray.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        //判断是否为空
        System.out.println(jsonObject.has("name"));

    }
}
